package factory;

import dao.impl.IntermediaryInvocationHandler;

import java.lang.reflect.Proxy;

public class IntermediarJdkProxyFactory {
    /**
     * 工厂方法
     *
     *
     */
    public static <T>T create(Object target){
        //IntermediaryInvocationHandler的成员变量存在线程安全问题
        //故将IntermediaryInvocationHandler作为局部变量使用
        IntermediaryInvocationHandler intermediaryInvocationHandler = new IntermediaryInvocationHandler();

        intermediaryInvocationHandler.setTarget(target);
        return (T) Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(),intermediaryInvocationHandler);
    }
}
